package com.ruoyi.web.controller.erp;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.IApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 审批Controller
 *
 * @author ruoyi
 * @date 2023-07-24
 */
@RestController
@RequestMapping("/erp/approval")
public class ApprovalController extends BaseController {

    @Autowired
    private IApprovalService approvalService;

    /**
     * 查询待审批订单列表
     */

    @GetMapping("/pending")
    public TableDataInfo pendingList() {
        return approvalService.selectPendingApprovals();
    }

    /**
     * 审批订单
     */

    @PutMapping("/{orderNumber}")
    public AjaxResult approve(
        @PathVariable String orderNumber,
        @RequestBody Map<String, String> params) {
        String approvalResult = params.get("approvalResult");
        String approvalNote = params.get("approvalNote");
        return toAjax(approvalService.approve(orderNumber, approvalResult, approvalNote));
    }
}
